﻿#ifndef _PCAPFILE_H_
#define _PCAPFILE_H_

#include <cstring>
#include <memory>
#include <vector>
#include <thread>
#include <chrono>
#include <functional>
#include <unordered_map>
#include <map>
#include <mutex>
#include <pcap.h>
#include <atomic>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>


namespace secsmart_pcap
{   

    #define NETPCAP_FILEMAXNUMS         20000       /*最大包粒度*/
    #ifndef MAX_PATH
    #define MAX_PATH 260
    #endif
    class netpcap_file;
    using pcapfile_sptr = std::shared_ptr<netpcap_file>;

    class netpcap_file 
    {
        public:
            std::string                 pcapfile_timestamp();
            std::string                 pcapfile_get_app_path(void);
            std::string                 pcapfile_get_app_name(void);
            std::string                 pcapfile_get_app_dir(void);
            bool                        pcapfile_dir_get(const std::string& dirPath, std::vector<std::string>& fileLists);
            bool                        pcapfile_dir_get(const std::string& dirPath, std::string suffix, std::vector<std::string>& fileLists);
            bool                        pcapfile_dir_is_exist(const std::string& dirPath);
            bool                        pcapfile_dir_create(const std::string& dirPath);
            bool                        pcapfile_dir_remove(const std::string& dirPath);
            bool                        pcapfile_dir_remove_current(const std::string& dirPath);
            bool                        pcapfile_file_is_exist(const std::string& filePath);
            bool                        pcapfile_file_create(const std::string& filePath);
            bool                        pcapfile_file_remove(const std::string& dirPath);
            inline void                 pcapfile_nums_update() { m_file_nums_++; };
            inline std::uint32_t        pcapfile_nums_get() { return m_file_nums_; };
            void                        pcapfile_limits_nums(std::uint32_t nums);
            inline std::uint32_t        pcapfile_limits_get(){return m_file_limits_;};
            void                        pcapfile_set_dir_path(const std::string& dir);
            void                        pcapfile_set_file_name(const std::string& filename);
            std::string                 pcapfile_open_new_file();
        private:
            bool                        pcapfile_dir_list(const std::string& dirPath, std::string suffix);
        private:
            std::string                 m_file_name_;
            std::string                 m_dir_path_;
            std::uint32_t               m_file_nums_;
            std::uint32_t               m_file_index_;
            std::uint32_t               m_file_limits_;
            std::vector<std::string>    m_file_vector_; 
        public:
            netpcap_file():
                m_file_name_(""),
                m_dir_path_(""),
                m_file_nums_(0),
                m_file_index_(0),
                m_file_limits_(NETPCAP_FILEMAXNUMS) {};
            virtual ~netpcap_file() {};
            netpcap_file(const netpcap_file&) = delete;
            netpcap_file& operator=(const netpcap_file&) = delete;
    };









}



#endif
